﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;

namespace HRM.UI.HRManagerUI.EmpModule
{
    public partial class AddEmployeeContacts : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (Session["empCode"] != null)
                {
                    employeeCode.InnerText = Session["empCode"].ToString();
                    textboxCode.Visible = false;
                }
                else
                {
                    Label1.Visible = false;
                    employeeCode.Visible = false;
                    employeeCode.InnerText = "";
                }

            }

        }

        public void SaveContact(object o, EventArgs e)
        {
            try
            {
                ContactManager manager = new ContactManager();
                Contact contact = new Contact();
                Code code = new Code();
                Employee employee = new Employee();
                if (employeeCode.InnerText != "")
                {
                    code.CodeName = employeeCode.InnerText;
                }
                else
                {
                    code.CodeName = txtEmpCode.Value;
                }

                employee.EmpCode = code;
                contact.Employee = employee;
                contact.FirstContact = txtFirstcontact.Value;
                contact.Secondcontact = txtSecondContact.Value;
                contact.EmergencyContactPerson = txtEmergencyperson.Value;
                contact.EmergencyContactNumber = txtEmergencyNumber.Value;
                contact.PresentAddress = txtPresentAddress.Value;
                contact.PermanentAddress = txtPermanentAddress.Value;
                string msg = manager.SaveContactInfo(contact);
                msgLabel.Text = msg;
                if (msg.Contains("Successfully"))
                {
                    ClearInput();
                    msgLabel.ForeColor = Color.Green;
                    msgLabel.Font.Bold = true;
                    msg = "Contact Info Saved Successfully";

                }
                else
                {
                    msgLabel.ForeColor = Color.Red;
                    msgLabel.Font.Bold = true;
                    msg = "Contact not Saved !Try Again";
                }


            }
            catch (Exception)
            {

                throw;
            }

        }
        protected void ClearInput()
        {
            txtFirstcontact.Value = "";
            txtEmergencyperson.Value = "";
            txtEmergencyNumber.Value = "";
            txtPresentAddress.Value = "";
            txtPermanentAddress.Value = "";
            txtSecondContact.Value = "";
        }
    }
}